#ifndef LIB_IO_H
#define LIB_IO_H

/*write a byte to a port*/
static inline void outb(uint16_t port,uint8_t data)
{
	asm volatile ("outb %b0,%w1"::"a"(data),"d"(port));
}

/*write word_cnt byte to port from addr*/
static inline void outsw(uint16_t port,const void* addr,uint32_t word_cnt)
{
	asm volatile ("cld; rep outsw":"+S"(addr),"+c"(word_cnt):"d"(port));
}

/*read a byte from port*/
static inline uint8_t inb(uint16_t port)
{
	uint8_t data;
	asm volatile ("inb %w1,%b0":"=a"(data):"d"(port));
	return data;
}

/*read word_cnt word from port to addr*/
static inline void insw(uint16_t port,void* addr,uint32_t word_cnt)
{
	asm volatile ("cld;rep insw":"+D"(addr),"+c"(word_cnt):"d"(port):"memory");
}

#endif
